/**
 * @class Prototype UI Extension creates a tree view based on a nested UL/LI construct.
 *   
 * @author embrace.toolkit
 * @public
 * @version $Id: TableSorter.js 78 2009-09-29 07:15:26Z embrace.toolkit $
 */
eui.TreeView.TreeView = Class.create({
	/** @lends eui.TreeView.TreeView */
	/**
	 * referenced Dom element
	 * @private
	 */
	element: false,
	/**
	 * Called by constructor.
	 * @param eui.TreeView.Options
	 * @public
	 */
	initialize: function(parameters) {
		if(!parameters.element || !$(parameters.element))	
			throw("NullException: Element can not be null.");
		
		this.element = $(parameters.element);
		this.setupMouseEvents();
	},
	/**
	 * Registeres all mouse listeners(observers) needed in the tree control.
	 * @private
	 */
	setupMouseEvents: function() {
		this.collapseAll();
		this.element.addClassName("expandable");
		this.element.observe("click", this.expandItem.bind(this));
	},
	/**
	 * Expands the clicked item.
	 * @private
	 * @param Event clickEvent the notified mouse event
	 * @event click
	 */
	expandItem: function(clickEvent) {
		this.element.select(
				"[branch!=" + clickEvent.findElement().readAttribute("node") + "]"
			).invoke("hide");
		
		this.element.select(
			"[branch=" + clickEvent.findElement().readAttribute("node") + "]"
		).invoke("show");
	},
	/**
	 * Collapses all nodes.
	 * @public
	 */
	collapseAll: function() {
		this.element.childElements().invoke("hide");
		this.element.select("li").invoke("show");
	}
});

/**
 * Creates a eui.TreeView.Options object.
 * @sees eui.TreeView.TreeView#initialize
 * @class Parameters for creating a tree view object.
 * @public
 * @example
 * <p>You can youse the classical OOP way like this:
 * 	<code>
 *var treeOptions = new eui.TreeView.Options();
 *treeOptions.element = "tree";
 * 	</code>
 * Or the inline way like:
 * 	<code>
 *var treeOptions = {
 *	element: "tree"
 *};
 * 	</code>
 * </p>
 * <p>Both ways are functional, because {@link eui.TreeView.Options} is 
 * only an interface how to setup {@link eui.TreeView}.
 */
eui.TreeView.Options = Class.create({
	element: false
});